// import type { Fetcher } from 'swr'
// import qs from 'qs'
// import { del, get, patch, post, put } from './base'
import type {
    CreateDocumentReq,
    DataSet,
    DataSetListResponse,
    DocumentDetailResponse,
    DocumentListResponse,
    ErrorDocsResponse,
    ExternalAPIDeleteResponse,
    ExternalAPIItem,
    ExternalAPIListResponse,
    ExternalAPIUsage,
    ExternalKnowledgeBaseHitTestingResponse,
    ExternalKnowledgeItem,
    FileIndexingEstimateResponse,
    HitTestingRecordsResponse,
    HitTestingResponse,
    IndexingEstimateParams,
    IndexingEstimateResponse,
    IndexingStatusBatchResponse,
    IndexingStatusResponse,
    ProcessRuleResponse,
    RelatedAppResponse,
    SegmentDetailModel,
    SegmentUpdater,
    SegmentsQuery,
    SegmentsResponse,
    createDocumentResponse,
} from '@/models/datasets'
// import type { CreateKnowledgeBaseReq } from '@/components/datasets/external-knowledge-base/create/declarations'
// import type { CreateExternalAPIReq } from '@/components/datasets/external-api/declarations'
import type { CommonResponse, DataSourceNotionWorkspace } from '@/models/common'
import { DataSourceProvider } from '@/models/common'
import type {
    ApiKeysListResponse,
    CreateApiKeyResponse,
} from '@/models/app'
import type { RetrievalConfig } from '@/services/types/app'

// apis for documents in a dataset

type CommonDocReq = {
    datasetId: string
    documentId: string
}

type BatchReq = {
    datasetId: string
    batchId: string
}
type Fetcher<T, M> = any;

export type SortType = 'created_at' | 'hit_count' | '-created_at' | '-hit_count'

export type MetadataType = 'all' | 'only' | 'without'

export const fetchDatasetDetail = (datasetId: string) => {

    return {} as any
}

export const updateDatasetSetting: Fetcher<DataSet, {
    datasetId: string
    body: Partial<Pick<DataSet,
        'name' | 'description' | 'permission' | 'partial_member_list' | 'indexing_technique' | 'retrieval_model' | 'embedding_model' | 'embedding_model_provider'
    >>
}> = ({ datasetId, body }) => {

    return {} as any
}

export const fetchDatasetRelatedApps: Fetcher<RelatedAppResponse, string> = (datasetId: string) => {

    return {} as any
}

export const fetchDatasets: Fetcher<DataSetListResponse, { url: string; params: { page: number; ids?: string[]; limit?: number } }> = ({ url, params }) => {

    return {} as any
}

export const createEmptyDataset: Fetcher<DataSet, { name: string }> = ({ name }) => {

    return {} as any
}

export const checkIsUsedInApp: Fetcher<{ is_using: boolean }, string> = (id) => {

    return {} as any
}

export const deleteDataset: Fetcher<DataSet, string> = (datasetID) => {

    return {} as any
}

export const fetchExternalAPIList: Fetcher<ExternalAPIListResponse, { url: string }> = ({ url }) => {

    return {} as any
}

export const fetchExternalAPI: Fetcher<ExternalAPIItem, { apiTemplateId: string }> = ({ apiTemplateId }) => {

    return {} as any
}

export const updateExternalAPI: Fetcher<ExternalAPIItem, { apiTemplateId: string; body: ExternalAPIItem }> = ({ apiTemplateId, body }) => {

    return {} as any
}
export const deleteExternalAPI: Fetcher<ExternalAPIDeleteResponse, { apiTemplateId: string }> = ({ apiTemplateId }) => {

    return {} as any
}

export const checkUsageExternalAPI: Fetcher<ExternalAPIUsage, { apiTemplateId: string }> = ({ apiTemplateId }) => {

    return {} as any
}

export const createExternalAPI: Fetcher<ExternalAPIItem, { body: any }> = ({ body }) => {

    return {} as any
}

export const createExternalKnowledgeBase: Fetcher<ExternalKnowledgeItem, { body: any }> = ({ body }) => {

    return {} as any
}

export const fetchDefaultProcessRule: Fetcher<ProcessRuleResponse, { url: string }> = ({ url }) => {

    return {} as any
}
export const fetchProcessRule: Fetcher<ProcessRuleResponse, { params: { documentId: string } }> = ({ params: { documentId } }) => {

    return {} as any
}

export const fetchDocuments: Fetcher<DocumentListResponse, { datasetId: string; params: { keyword: string; page: number; limit: number; sort?: SortType } }> = ({ datasetId, params }) => {

    return {} as any
}

export const createFirstDocument: Fetcher<createDocumentResponse, { body: CreateDocumentReq }> = ({ body }) => {

    return {} as any
}

export const createDocument: Fetcher<createDocumentResponse, { datasetId: string; body: CreateDocumentReq }> = ({ datasetId, body }) => {

    return {} as any
}

export const fetchIndexingEstimate: Fetcher<IndexingEstimateResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}
export const fetchIndexingEstimateBatch: Fetcher<IndexingEstimateResponse, BatchReq> = ({ datasetId, batchId }) => {

    return {} as any
}

export const fetchIndexingStatus: Fetcher<IndexingStatusResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const fetchIndexingStatusBatch: Fetcher<IndexingStatusBatchResponse, BatchReq> = ({ datasetId, batchId }) => {

    return {} as any
}

export const fetchDocumentDetail: Fetcher<DocumentDetailResponse, CommonDocReq & { params: { metadata?: MetadataType } }> = ({ datasetId, documentId, params }) => {

    return {} as any
}

export const renameDocumentName: Fetcher<CommonResponse, CommonDocReq & { name: string }> = ({ datasetId, documentId, name }) => {

    return {} as any
}

export const pauseDocIndexing: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const resumeDocIndexing: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const deleteDocument: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const archiveDocument: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const unArchiveDocument: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const enableDocument: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const disableDocument: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const syncDocument: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const syncWebsite: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => {

    return {} as any
}

export const preImportNotionPages: Fetcher<{ notion_info: DataSourceNotionWorkspace[] }, { url: string; datasetId?: string }> = ({ url, datasetId }) => {

    return {} as any
}

export const modifyDocMetadata: Fetcher<CommonResponse, CommonDocReq & { body: { doc_type: string; doc_metadata: Record<string, any> } }> = ({ datasetId, documentId, body }) => {

    return {} as any
}

// apis for segments in a document

export const fetchSegments: Fetcher<SegmentsResponse, CommonDocReq & { params: SegmentsQuery }> = ({ datasetId, documentId, params }) => {

    return {} as any
}

export const enableSegment: Fetcher<CommonResponse, { datasetId: string; segmentId: string }> = ({ datasetId, segmentId }) => {

    return {} as any
}

export const disableSegment: Fetcher<CommonResponse, { datasetId: string; segmentId: string }> = ({ datasetId, segmentId }) => {

    return {} as any
}

export const updateSegment: Fetcher<{ data: SegmentDetailModel; doc_form: string }, { datasetId: string; documentId: string; segmentId: string; body: SegmentUpdater }> = ({ datasetId, documentId, segmentId, body }) => {

    return {} as any
}

export const addSegment: Fetcher<{ data: SegmentDetailModel; doc_form: string }, { datasetId: string; documentId: string; body: SegmentUpdater }> = ({ datasetId, documentId, body }) => {

    return {} as any
}

export const deleteSegment: Fetcher<CommonResponse, { datasetId: string; documentId: string; segmentId: string }> = ({ datasetId, documentId, segmentId }) => {

    return {} as any
}

export const segmentBatchImport: Fetcher<{ job_id: string; job_status: string }, { url: string; body: FormData }> = ({ url, body }) => {

    return {} as any
}

export const checkSegmentBatchImportProgress: Fetcher<{ job_id: string; job_status: string }, { jobID: string }> = ({ jobID }) => {

    return {} as any
}

// hit testing
export const hitTesting: Fetcher<HitTestingResponse, { datasetId: string; queryText: string; retrieval_model: RetrievalConfig }> = ({ datasetId, queryText, retrieval_model }) => {

    return {} as any
}

export const externalKnowledgeBaseHitTesting: Fetcher<ExternalKnowledgeBaseHitTestingResponse, { datasetId: string; query: string; external_retrieval_model: { top_k: number; score_threshold: number; score_threshold_enabled: boolean } }> = ({ datasetId, query, external_retrieval_model }) => {

    return {} as any
}

export const fetchTestingRecords: Fetcher<HitTestingRecordsResponse, { datasetId: string; params: { page: number; limit: number } }> = ({ datasetId, params }) => {

    return {} as any
}

export const fetchFileIndexingEstimate: Fetcher<FileIndexingEstimateResponse, IndexingEstimateParams> = (body: IndexingEstimateParams) => {

    return {} as any
}

export const fetchNotionPagePreview: Fetcher<{ content: string }, { workspaceID: string; pageID: string; pageType: string }> = ({ workspaceID, pageID, pageType }) => {

    return {} as any
}

export const fetchApiKeysList: Fetcher<ApiKeysListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {

    return {} as any
}

export const delApikey: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {

    return {} as any
}

export const createApikey: Fetcher<CreateApiKeyResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {

    return {} as any
}

export const fetchDatasetApiBaseUrl: Fetcher<{ api_base_url: string }, string> = (url) => {

    return {} as any
}

export const fetchDataSources = () => {

    return {} as any
}

export const createDataSourceApiKeyBinding: Fetcher<CommonResponse, Record<string, any>> = (body) => {

    return {} as any
}

export const removeDataSourceApiKeyBinding: Fetcher<CommonResponse, string> = (id: string) => {

    return {} as any
}

export const createFirecrawlTask: Fetcher<CommonResponse, Record<string, any>> = (body) => {

    return {} as any
}

export const checkFirecrawlTaskStatus: Fetcher<CommonResponse, string> = (jobId: string) => {

    return {} as any
}

export const createJinaReaderTask: Fetcher<CommonResponse, Record<string, any>> = (body) => {

    return {} as any
}

export const checkJinaReaderTaskStatus: Fetcher<CommonResponse, string> = (jobId: string) => {

    return {} as any
}

type FileTypesRes = {
    allowed_extensions: string[]
}

export const fetchSupportFileTypes: Fetcher<FileTypesRes, { url: string }> = ({ url }) => {

    return {} as any
}

export const getErrorDocs: Fetcher<ErrorDocsResponse, { datasetId: string }> = ({ datasetId }) => {

    return {} as any
}

export const retryErrorDocs: Fetcher<CommonResponse, { datasetId: string; document_ids: string[] }> = ({ datasetId, document_ids }) => {

    return {} as any
}
